package com.example.mybatis.controller;

import com.example.mybatis.dto.UserDTO;
import com.example.mybatis.dto.ValidList;
import com.example.mybatis.service.impl.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.util.List;

@RestController
@Validated
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/")
    public Object test() {
        List<UserDTO> userDTOS = userService.getAllUser();
        return userDTOS;
    }

    @GetMapping("/vo")
    public Object testVo() {
        List<UserDTO> userDTOS = userService.getAllUser();
        return userDTOS;
    }

    @PostMapping("/save")
    public Object save(@RequestBody @Valid ValidList list) {
        List<UserDTO> userDTOS = userService.getAllUser();
        return userDTOS;
    }

    @GetMapping("/validated")
    public Object save(@NotBlank(message = "name不可为空") String name) {
        List<UserDTO> userDTOS = userService.getAllUser();
        return userDTOS;
    }
}
